Uec3.DepartmentAddWindow = Ext.extend(Ext.app.Module, {
	id : 'departmentAdd',
	type : 'common/departmentAdd',

	/**
	 * Initialize this module. This function is called at startup (page
	 * load/refresh).
	 */
	init : function(initParams) {

	},
	getComponents : function(scope) {

		var department_form;
		var department_ajax;

		var componentInitsDepartment = function() {

			department_ajax = new Ext.data.Connection();

			// 初始化表单对象
			department_form = new Ext.form.FormPanel({
				labelAlign : 'right',
				labelWidth : 60,
				// title:客户档案,
				frame : true,
				width : 310,
				autoHeight : true,
				url : '',
				items : [{
							layout : 'form',
							defaultType : 'textfield',
							items : [{
										name : 'name',
										fieldLabel : '部门名称',
										width : 180,
										allowBlank:false,
						                blankText:"部门名称不能为空"
									}]
						}],
				buttons : [{
					text : '保存',
					handler : function() {
						if (!department_form.getForm().isValid()) {
							Ext.Msg.alert("提示", "请按要求进行正确的操作");
							return;

						}
						var formValues = department_form.getForm().getValues();
						var jsonAll = Ext.encode(formValues);
						department_ajax.request({
									url : Uec3.App.Constants.homeUrl
											+ '/department/base!save.do',
									success : function(res) {
										var result = Ext
												.decode(res.responseText);
										if (result.success == "OK") {

											var department = result.department;
											scope.setLookupValue({
														"name" : department.name,
														"pyCode" : department.pyCode,
														"id" : department.id
													}, department_form.ownerCt);
											department_form.ownerCt.close();

										} else {

											Ext.Msg
													.alert("提示",
															result.failure);

										}
									},

									failure : function(res) {

										Ext.Msg.alert('失败', "网络出现异常，请重先登入");

									},

									params : {
										jsonAll : jsonAll
									}

								});

					}

				}, {
					text : '取消',

					handler : function() {

						department_form.ownerCt.close();

					}

				}],
				buttonAlign : 'center'
			});

		};

		var controlDepartmentEvent = function() {

			department_ajax.on('beforerequest', function() {

						Ext.MessageBox.wait("保存数据中...", "提示");
					});

			department_ajax.on('requestcomplete', function() {

						Ext.MessageBox.hide();
					});

		};

		componentInitsDepartment();

		controlDepartmentEvent();

		return department_form;

	},

	/**
	 * Create this modules window here.
	 */
	createWindow : function() {
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('departmentAdd');
		if (!win) {
			win = desktop.createWindow({
						id : 'departmentAdd',
						title : '增加部门',
						width:350,
						autoHeight : true,
						iconCls : 'acc-icon',
						shim : false,
						modal : true,
						animCollapse : false,
						constrainHeader : true,
						maximizable : false,
						taskbuttonTooltip : "增加部门",
						layout : "fit",
						resizable : false,
						items : [this.getComponents(this)]
					});

		}
		win.show();

	}
});